package com.lovo.pz.role;

import com.lovo.pz.util.GameUtil;
import com.lovo.pz.window.GamePanel;

import java.awt.*;

/**
 * 植物卡片角色
 * @author 白德柯
 *
 */
public class PlantCardRole extends BaseRole{
    /** 豌豆射手类型 */
    public static final int PEA_SHOOTER = 0;
    /** 太阳花类型 */
    public static final int SUN_FLOWER = 1;
    /** 植物卡片的类型 */
    private int plantType;
    public PlantCardRole(Component component){
        super(component);
    }
    @Override
    public void initRole() {
        setRunStatus(CARD_DISABLED);
        setRoleWidth(GameUtil.plantsCardImage[0].getWidth(getComponent()));
        setRoleHeight(GameUtil.plantsCardImage[0].getHeight(getComponent()));
    }

    @Override
    public void paintRole(Graphics g) {
        if(plantType == PEA_SHOOTER){
            g.drawImage(GameUtil.plantsCardImage[0],getRoleX(),getRoleY(),getComponent());
        }else if(plantType == SUN_FLOWER){
            g.drawImage(GameUtil.plantsCardImage[1],getRoleX(),getRoleY(),getComponent());
        }
        if(getRunStatus() == CARD_DISABLED){
            GameUtil.setAlpha(g,0.5f);
        }else{
            GameUtil.setAlpha(g,0);
        }
        g.setColor(Color.BLACK);
        g.fillRect(getRoleX(),getRoleY(),getRoleWidth(),getRoleHeight());
        GameUtil.setAlpha(g,1);
    }

    @Override
    public void action() {
        GamePanel gamePanel = (GamePanel) getComponent();
        if(gamePanel.getPlantPanelRole().getSeedCnt() >= getCost()){
            setRunStatus(CARD_ENABLED);
        }else{
            setRunStatus(CARD_DISABLED);
        }
    }

    public int getPlantType() {
        return plantType;
    }

    public void setPlantType(int plantType) {
        this.plantType = plantType;
    }
}
